const regs = {
  phone: /^((1[0-9]))\d{9}$/,
  email: /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/,
  number: /^[0-9]*$/,
  password: /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z~!@#$%^&*]{8,}$/,
  account: /^[0-9a-zA-Z_]{1,}$/,
  // password: /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z~!@#$%^&*]{8,}$/
  // 区分大小写，必须有数字+字母，允许包含12345678 按键的特殊字符，8-20位
  pInt: /^[1-9]+[0-9]*$/, //正整数
  pointNumber: /^([1-9]\d{0,9}|0)([.]?|(\.\d{1,10})?)$/, //小数
  money: /^(([0-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/, //金额
}
const verify = (rule, value, callback, reg, msg) => {
  if (value) {
    if (reg.test(value)) {
      callback()
    } else {
      return callback(new Error(rule.message))
    }
  } else {
    callback()
  }
}

export default {
  phone: (rule, value, callback) => {
    return verify(rule, value, callback, regs.phone)
  },
  email: (rule, value, callback) => {
    return verify(rule, value, callback, regs.email)
  },
  number: (rule, value, callback) => {
    return verify(rule, value, callback, regs.number)
  },
  password: (rule, value, callback) => {
    return verify(rule, value, callback, regs.password)
  },
  account: (rule, value, callback) => {
    return verify(rule, value, callback, regs.account)
  },
  pInt: (rule, value, callback) => {
    return verify(rule, value, callback, regs.pInt)
  },
}
